﻿let L = window.L;
class YhglMap extends React.Component {
  constructor(ps) {
    super(ps);
  }

  //初始化地图
  initMap() {
    // $('#map').height(document.body.clientHeight - 241);
    var map = L.map('map', {
      center: [30.752264, 120.762075],
      zoom: 12,
      crs: L.CRS.EPSG4326,
      // minZoom: 10,
      // maxZoom: 16,
      attributionControl: false,
      zoomControl: false,
    });
    L.control
      .zoom({
        position: 'bottomright',
      })
      .addTo(map);

    const { GetMap } = this.props;

    L.tileLayer(
      'http://t{s}.tianditu.com/vec_c/wmts?layer=vec&style=default&tilematrixset=c&Service=WMTS&Request=GetTile&Version=1.0.0&Format=tiles&TileMatrix={z}&TileCol={x}&TileRow={y}&tk=85b88ce10c15f390ee75bf571688b3b7',
      {
        tileSize: 256,
        zoomOffset: 1,
        subdomains: '123456',
      }
    ).addTo(map);

    // 国家矢量注记地图服务
    L.tileLayer(
      'http://t{s}.tianditu.com/cva_c/wmts?layer=cva&style=default&tilematrixset=c&Service=WMTS&Request=GetTile&Version=1.0.0&Format=tiles&TileMatrix={z}&TileCol={x}&TileRow={y}&tk=85b88ce10c15f390ee75bf571688b3b7',
      {
        tileSize: 256,
        zoomOffset: 1,
        subdomains: '123456',
      }
    ).addTo(map);

    this.map = map;
    GetMap(this.map);

    // L.control.attribution({ prefix: '农村饮水安全工程信息化管控平台GIS模块' }).addTo(map);
    map.on('zoomend', function() {
      if (map.getZoom() < 12) {
      }
    });

    map.on('click', function(e) {
      if (e.target.id != 'plQueryPanel') {
      }
    });
  }

  componentDidMount() {
    this.initMap();
  }

  render() {
    return (
      <div id="map" style={{ height: 618, width: '100%', overflow: 'hidden', padding: 0 }} />
    );
  }
}

export default YhglMap;
